package lock;

import data_management.KeyguardData;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.widget.SeekBar;

public	class LockSlideEvent implements SeekBar.OnSeekBarChangeListener{
	private int state=0;
	private int sensitivity = 20;
	private int max = 100;
	private int default_progress = 7;
	private Intent next;
	private Activity activity;
	
	public LockSlideEvent(Activity activity){
		this.activity = activity;
	}
	public LockSlideEvent(Activity activity, SeekBar seekBar, Intent next){
		this(activity);
		setNext(next);
		
		seekBar.setMax(max);
		seekBar.setProgress(default_progress);
	}
	public void setNext(Intent next){
		this.next = next;
	}
	public void setSensitivity(int sensitivity){
		this.sensitivity = sensitivity;
		default_progress = sensitivity / 2;
	}
	
	private final int STOP  = 0;
	private final int READY = 1;
	private final int TRACK = 2;
	private final int DISABLE = 3;
	
	public void onStopTrackingTouch(SeekBar seekBar) {
		Log.d("STOP-seekBar:", ""+seekBar.getProgress());
		if(state == TRACK && seekBar.getProgress() < seekBar.getMax() - sensitivity){
			seekBar.setProgress(default_progress);
		}
		if(state == TRACK && seekBar.getProgress()>= seekBar.getMax() - sensitivity){
			seekBar.setProgress(seekBar.getMax() - default_progress);
			activity.startActivity(next);
			KeyguardData.keylock.disableKeyguard();
			activity.finish();
		}
		state = STOP;
	}
	public void onStartTrackingTouch(SeekBar seekBar) {
		state = READY;
	}
	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
		if(state == READY && progress < sensitivity){
			state = TRACK;
		}
		if(state == READY && progress >=sensitivity){
			state = DISABLE;
		}
		if(state == TRACK){}
		if(state == DISABLE){
			seekBar.setProgress(default_progress);
		}
	}
}